﻿using System;
using System.Collections.Generic;
using Resn.WhuPub.BIL;
using Resn.WhuPub.DAL;
using Resn.WhuPub.DML;

namespace Resn.WhuPub.BLL
{
        /// <summary>
        /// 实现员工分组管理器的属性与方法
        /// </summary>
        public class EmployeeManager:IEmployeeManager
        {

                #region 属性

                private static EmployeeManager _instance;

                /// <summary>
                /// 获取员工分组管理器实例
                /// </summary>
                /// <value>
                /// 员工分组管理器实例
                /// </value>
                public static EmployeeManager Instance
                {
                        get { return _instance ?? (_instance = new EmployeeManager()); }
                }

                /// <summary>
                /// 获取所有员工分组集合
                /// </summary>
                /// <returns>
                /// 所有员工分组集合
                /// </returns>
                public List<IEmployee> Employees
                {
                        get
                        {
                                var models = DBStorage.Instance.Select<EmployeeModel>();

                                var result = new List<IEmployee>();

                                models.ForEach(i => result.Add(new Employee(i)));

                                return result;
                        }
                }
                #endregion

                #region 方法


                
                /// <summary>
                /// 添加员工到本员工分组
                /// </summary>
                /// <param name="name">账号</param>
                /// <param name="password">密码</param>
                /// <param name="employeeLevel">层次</param>
                /// <returns></returns>
                public IEmployee CreateEmployee(string name, string password, EmployeeLevel employeeLevel)
                {
                        var model = new EmployeeModel
                        {
                                Id = Guid.NewGuid().ToString(),
                                Name = name,
                                Password = password,
                                EmployeeLevel = employeeLevel.ToString(),
                                EmployeeState = EmployeeState.在职.ToString()
                        };

                        return new Employee(model);
                }
                #endregion
        }
}